package com.frxuexi.base.net

import android.content.Context
import androidx.room.Room
import com.frxuexi.base.db.ParkDao
import com.frxuexi.base.db.ParkDataBase
import com.frxuexi.base.db.UserDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ProviderFactory {

    @Singleton
    @Provides
    fun apiServiceToken(): ApiService = getServiceToken()

    @Singleton
    @Provides
    fun apiServiceNews(): ApiServiceNews = getServiceNews()

    @Singleton
    @Provides
    fun database(@ApplicationContext context: Context):ParkDataBase=
        Room.databaseBuilder(context,ParkDataBase::class.java,"park2209.db")
            .allowMainThreadQueries()
            .build()

    @Singleton
    @Provides
    fun userDao(dataBase: ParkDataBase):UserDao=dataBase.getUserDao()

    @Singleton
    @Provides
    fun parkDao(dataBase: ParkDataBase):ParkDao=dataBase.getParkDao()
}